home *** CD-ROM | disk | FTP | other *** search
- unit Reclabel;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, DB, DBTables, Menus;
-
- const StateStr: array[TDataSetState] of string[10] =
- ('Closed', 'Browsing', 'Editing', 'Inserting', 'SetKey', 'CalcFields');
-
- type
- TRecDisplayType = (rdRecordNo, rdRecordNoOfCount);
-
- TDBRecLabel = class(TCustomLabel)
- private
- { Private declarations }
- FDataLink: TFieldDataLink;
- FDispType: TRecDisplayType;
- procedure DoDataChange(Sender: TObject);
- procedure DoActiveChange(Sender: TObject);
- procedure SetDataSource(const Value: TDataSource);
- procedure SetDispType(Value: TRecDisplayType);
- function GetDataSource: TDataSource;
- protected
- { Protected declarations }
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- public
- { Public declarations }
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- { Published declarations }
- property DisplayType: TRecDisplayType read FDispType write SetDispType default rdRecordNo;
- property DataSource: TDataSource read GetDataSource write SetDataSource;
- property Align;
- property Alignment;
- property AutoSize;
- property Color;
- property Enabled;
- property Font;
- property ParentColor;
- property ParentFont;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
- property Transparent;
- property Visible;
- property WordWrap;
- end;
-
- procedure Register;
-
- implementation
-
- uses DbiTypes, DbiProcs;
-
- constructor TDBRecLabel.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FDataLink := TFieldDataLink.Create;
- FDataLink.OnDataChange := DoDataChange;
- FDataLink.OnActiveChange := DoActiveChange;
- FDispType := rdRecordNo;
- end;
-
- destructor TDBRecLabel.Destroy;
- begin
- FDataLink.OnDataChange := nil;
- FDataLink.OnActiveChange := nil;
- FDataLink.Free;
- inherited Destroy;
- end;
-
- procedure TDBRecLabel.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- inherited Notification(AComponent, Operation);
- if (Operation = opRemove) and (AComponent = DataSource) then
- FDataLink.DataSource := nil;
- end;
-
- procedure TDBRecLabel.DoActiveChange(Sender: TObject);
- begin
- if (DataSource <> nil) then
- begin
- Caption := StateStr[DataSource.State];
- if DataSource.State = dsBrowse then DoDataChange(Self);
- end
- else
- if csDesigning in ComponentState then
- Caption := Self.Name
- else
- Caption := '';
- end;
-
- procedure TDBRecLabel.DoDataChange(Sender: TObject);
- var RecNo: LongInt;
- begin
- if FDataLink.DataSource.State = dsBrowse then
- with FDataLink.DataSource.DataSet do
- begin
- UpdateCursorPos;
- Check(DbiGetSeqNo(Handle, RecNo));
- case FDispType of
- rdRecordNo: Caption := format('Record %d', [RecNo]);
- rdRecordNoOfCount: Caption := format('Record %d of %d', [RecNo, RecordCount]);
- end
- end
- else
- Caption := StateStr[FDataLink.DataSource.State];
- end;
-
- procedure TDBRecLabel.SetDataSource(const Value: TDataSource);
- begin
- FDataLink.DataSource := Value;
- end;
-
- function TDBRecLabel.GetDataSource: TDataSource;
- begin
- Result := FDataLink.DataSource;
- end;
-
- procedure TDBRecLabel.SetDispType(Value: TRecDisplayType);
- begin
- FDispType := Value;
- end;
-
- procedure Register;
- begin
- RegisterComponents('JOC', [TDBRecLabel]);
- end;
-
- end.
-